package com.huadi.firematerialident.dao;

import com.huadi.firematerialident.po.FireInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Repository
public class FireInfoDaoImpl implements FireInfoDao{

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    public int addFireInfo(FireInfo fireinfo) {

        String sql="insert into fireinfo values(?,?,?,?,?,?,'否',1,now())";
        return jdbcTemplate.update(sql,
                fireinfo.getFireInfoID(),
                fireinfo.getFireType(),
                fireinfo.getFireLevel(),
                fireinfo.getFireTime(),
                fireinfo.getFireAdd(),
                fireinfo.getMoreInfo());
    }

    @Override
    public int deleteFireInfoByID(String fireinfoID) {
        String sql="update fireinfo set LogicalAddDel=0 ,LastModification=now() where FireInfoID=?";
        return jdbcTemplate.update(sql,fireinfoID);
    }

    @Override
    public int updateFireInfo(FireInfo fireInfo) {
        String sql="update fireinfo set FireInfoID=?,FireType=?,FireLevel=?,FireTime=?," +
                "FireAdd=?,MoreInfo=?,ArchivingStatus=?,LastModification=now() where FireInfoID=?";
        return jdbcTemplate.update(sql,
                fireInfo.getFireInfoID(),
                fireInfo.getFireType(),
                fireInfo.getFireLevel(),
                fireInfo.getFireTime(),
                fireInfo.getFireAdd(),
                fireInfo.getMoreInfo(),
                fireInfo.getArchivingStatus(),
                fireInfo.getFireInfoID());
    }

    @Override
    public List<Map<String,Object>> selectFireInfoByID(String fireinfoID) {
        String sql="select * from fireinfo where FireInfoID = ?";
        return jdbcTemplate.queryForList(sql,fireinfoID);
    }

    @Override
    public List<Map<String,Object>> getAllFireInfo() {
        String sql="select * from fireinfo";
        return jdbcTemplate.queryForList(sql);
    }
}
